<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #tableButtons>
        <button-group :button-groups="buttonGroups" :crud-ref="crudRef" :selected="selected" :currentStatus="currentStatus"/>
        <download url="finance/bouus/export" type="bouus" :auth="['finance:bouus:export']"/>
      </template>
      <template #amount="{ record }">
          {{record.amount}} <a-tag v-if="record.estimation == 1" size="small" color="blue">估</a-tag>
      </template>
      <template #status="{ record }">
        <a-tag v-if="record.status == 1" size="small" color="green">已审计</a-tag>
        <a-tag v-if="record.estimation == 1" size="small" color="gray">不可审计</a-tag>
        <a-tag v-if="record.status == 0 && record.estimation == 0" size="small" color="red">未审计</a-tag>
      </template>
    </ma-crud>
    <batch-action-modal v-model="batch.visible"
    :crud-ref="crudRef"
    :selected="selected"
    ref="batchActionRef"
    ></batch-action-modal>
  </div>
</template>
<script setup>
import { ref, reactive ,computed,provide} from 'vue'
import bonus from '@/api/finance/bonus'
import BatchActionModal from "@cps/actions/batchActionModal.vue";
import ButtonGroup from "@cps/actions/buttonGroup.vue";
import dicthelper from "@/utils/dicthelp.js";
import {getDictData} from "@/utils/crud/dict.js";
import Download from "@/views/components/download.vue";
const batchActionRef = ref()
const crudRef = ref()
const batch = ref({visible:false,})
const selected = computed(()=>crudRef.value?.selecteds)
const buttonGroups = [
  {title:'放入提成单',api:bonus.billIn,displayDataIndex:"id",
    auth:['finance:bonus:bill'],  
    form:{
      form:{
        test:1
      },
      columns:[
        {
          title: "账单",
          dataIndex: "bill_id",
          formType: "select",
          dict: {
            url: 'finance/bonusPercentageBill/list',
            props: {label:(record)=>{ return getDictData('user_id',record.user_id,crudRef)+'--'+ record.created_at }, value: 'id'},
            params: {select: 'id,bill_number,user_id,created_at',status:"1"},
          }, 
        },
      ]
    }
  },
  {title:'通过审计',api:bonus.auditPass,displayDataIndex:"id",auth:['finance:bonus:pass']
    
  },
  {title:'反审计',api:bonus.auditRefuse,displayDataIndex:"id",auth:['finance:bonus:refuse']

  },
  {title:'查看统计',displayDataIndex:"id",
    
  },
  
]




const options = reactive({
  id: 'bonus',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  // operationColumn: true,
  // operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: "80%",
    layout: [{
        formType: 'grid-tailwind',
        colNumber: 1,
        cols: [
          {
            formList: [
              {dataIndex: "business_at"},
              {dataIndex: "fee_type"},
              {dataIndex: "currency"},
              {dataIndex: "unit"},
              {dataIndex: "exchange_rate"},
              {dataIndex: "unit_amount"},
              {dataIndex: "memo"},
              {dataIndex: "remark"},
            ]
          }
        ]
      }]
  },
  api: bonus.getList,
  recycleApi: bonus.getRecycleList,
  add: {
    show: true,
    api: bonus.save,
    auth: ['finance:bonus:save']
  },
  edit: {
    show: true,
    api: bonus.update,
    auth: ['finance:bonus:update']
  },
  delete: {
    show: true,
    api: bonus.deletes,
    auth: ['finance:bonus:delete'],
    realApi: bonus.realDeletes,
    realAuth: ['finance:bonus:realDeletes']
  },
  recovery: {
    show: true,
    api: bonus.recoverys,
    auth: ['finance:bonus:recovery']
  },
  export: {
    show: true,
    url: 'finance/bonus/export',
    auth: ['finance:bonus:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    // hide: true,
  },
  {
    title: "流水号",
    dataIndex: "fs_number",
    formType: "input",
    addDisplay:false,
    editDisplay:false,
    hide: true
  },
  {
    title: "运单号",
    dataIndex: "invoices_id",
    formType: "input",
    addDisplay:false,
    editDisplay:false,
    customRender: ({record}) => {
      return record.invoices?.shipment_no
    }
  },
  {
    title: "单据类型",
    dataIndex: "invoices_type",
    formType: "select",
    addDisplay:false,
    editDisplay:false,
    dict: {
      data:[
        {
          label: '运单',
          value: 'App\\Document\\Model\\Shipment'
        },
        {
          label: '提单',
          value: 'App\\Document\\Model\\Waybill'
        },
      ],
      translation: true,
    },
  },
  {
    title: "销售",
    dataIndex: "user_id",
    formType: "select",
    addDisplay:false,
    editDisplay:false,
    dict: dicthelper.user,
    search: true
  },
  {
    title: "收费名称",
    dataIndex: "name",
    addDisplay:false,
    editDisplay:false,
    formType: "input",
  },
  {
    title: "计费重",
    dataIndex: "fee_num",
    addDisplay:false,
    editDisplay:false,
    formType: "input",
  },
  {
    title: "单位",
    dataIndex: "unit",
    formType: "select",
    commonRules: {
      required: true,
      message: "请输入单位"
    },
    dict: {name: "ChargeType",translation: true,},
  },
  {
    title: "币种",
    dataIndex: "currency",
    formType: "select",
    search:true,
    dict: {
      name: "currencyType",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
      },
    commonRules: {
      required: true,
      message: "请输入币种"
    }
  },
  {
    title: "费用类型",
    dataIndex: "fee_type.fee_name",
    formType: "select",
  },
  {
    title: "费用类型",
    dataIndex: "fee_type",
    formType: "select",
    hide:true,
    search:true,
    dict: {
        url: 'finance/feeType/list',
        props: {label: 'fee_name', value: 'id'} ,
        params: {select: 'id,fee_name'},
        translation: true,
      },  
  },
  {
    title: "单位费用",
    dataIndex: "unit_amount",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入单位费用"
    }
  },
  {
    title: "总金额",
    dataIndex: "amount",
    formType: "input",
    addDisplay:false,
    editDisplay:false,
  },
  {
    title: "审计状态",
    dataIndex: "status",
    formType: "select",
    search: true,
    dict:{
      data: [
        {
          label: "已审计",
          value: 1
        },
        {
          label: "未审计",
          value: 0
        }
      ],
      translation: true
    },
    addDisplay:false,
    editDisplay:false,
  },
  {
    title: "汇率",
    dataIndex: "exchange_rate",
    formType: "input"
  },
  {
    title: "描述",
    dataIndex: "memo",
    formType: "input"
  },
  {
    title: "业务时间",
    dataIndex: "business_at",
    formType: "date",
    search: true,
    showTime: true,
    commonRules: {
      required: true,
      message: "请输入业务时间"
    }
  },
  {
    title: "账单id",
    dataIndex: "bill_id",
    addDisplay:false,
    editDisplay:false,
    formType: "input",
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
  }
])
provide('crudRef', crudRef)
</script>
<script> export default { name: 'finance:bonus' } </script>